package cn.cs.service.impl;

import cn.cs.client.RestClientUserClient;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.ClientRepRel;
import cn.cs.pojo.ClientUser;
import cn.cs.service.ClientUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ClientUserServiceImpl implements ClientUserService {

    @Resource
    private RestClientUserClient restClientUserClient;

    public ClientUser getClientUserById(String id)throws Exception{
        return restClientUserClient.getClientUserById(id);
    }

    public ClientUser getClientUserByAccount(String account)throws Exception{
        return restClientUserClient.getClientUserByAccount(account);
    }

    public ClientUser getClientUserByPhone(String phone)throws Exception{
        return restClientUserClient.getClientUserByPhone(phone);
    }

    public ClientUser getClientUserByOpenIdAccountNull(String openId)throws Exception{
        return restClientUserClient.getClientUserByOpenIdAccountNull(openId);
    }

    public List<ClientUser>	getClientUserListByMap(Map<String,Object> param)throws Exception{
        return restClientUserClient.getClientUserListByMap(param);
    }

    public Integer getClientUserCountByMap(Map<String,Object> param)throws Exception{
        return restClientUserClient.getClientUserCountByMap(param);
    }

    public Integer addClientUser(ClientUser clientUser)throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        clientUser.setCreateTime(sdf.format(new Date()));
            return restClientUserClient.insertClientUser(clientUser);
    }

    public Integer modifyClientUser(ClientUser clientUser)throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        clientUser.setUpdateTime(sdf.format(new Date()));
        return restClientUserClient.updateClientUser(clientUser);
    }

    public Integer modifyClientUserByOpenId(ClientUser clientUser)throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        clientUser.setUpdateTime(sdf.format(new Date()));
        return restClientUserClient.updateClientUserByOpenId(clientUser);
    }

    public Integer deleteClientUserById(String id)throws Exception{
        return restClientUserClient.deleteClientUserById(id);
    }

    public Page<ClientUser> queryClientUserPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize)throws Exception{
        Integer total = restClientUserClient.getClientUserCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? 1 : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? 10 : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ClientUser> clientUserList = restClientUserClient.getClientUserListByMap(param);
        page.setRows(clientUserList);
        return page;
    }

    @Override
    public ClientUser getClientUserByOpenId(String openId) throws Exception{
        return restClientUserClient.getClientUserByOpenId(openId);
    }

    public Integer itriptxAddClientRepRel(ClientRepRel clientRepRel) throws Exception{
        return restClientUserClient.insertClientRepRel(clientRepRel);
    }

    public Integer updateClientRepRel(ClientRepRel clientRepRel) throws Exception{
        return restClientUserClient.updateClientRepRel(clientRepRel);
    }

    public Map<String, Object> getWxVersionCode() throws  Exception{
        return restClientUserClient.getWxVersionCode();
    }
    public Integer setWxVersionCode(String versionCode)throws Exception{
        return restClientUserClient.setWxVersionCode(versionCode);
    }

    public List<Map<String, Object>> getUserByRepUserId(String rep_user_id)throws Exception{
        return restClientUserClient.getUserByRepUserId(rep_user_id);
    }

    public Integer saveUserScoreHistory(Map<String, Object> map)throws Exception{
        return restClientUserClient.saveUserScoreHistory(map);
    }
    public List<Map<String, Object>> getUserScoreHistoryByUserId(String userId)throws Exception{
        return restClientUserClient.getUserScoreHistoryByUserId(userId);
    }

}
